package com.wiley.homePO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class ExcellentReadingPage extends BasePage {
	
	LoggerControler log;

	/**
	 * 页面元素
	 */
	//精品阅读
	public static final By excellent_reading_loc = By.name("精品阅读");
	
	//列表image
	public static final By excellent_reading_image_loc = By.id(BaseId + "image");
	
	//详情页面title
	public static final By excellent_reading_titel_loc = By.id(BaseId + "title");
	
	/**
	 * 操作方法
	 */
	//点击精品阅读
	public void clickExcellentReading(){
		this.clickEle(excellent_reading_loc);
	}
	
	//循环访问image
	public void clickExcellentReadingImage(){
		int imageSize = this.getElesLength(excellent_reading_image_loc);
		for(int i = 0; i < imageSize; i++){
			this.clickEles(excellent_reading_image_loc, i);
			log.info("点击第"+(i+1)+"个精品阅读");
			log.info("该title为："+this.getExcellentReadingName());
			driver.sendKeyEvent(4);
		}
	}

	//获取reading标题
	public String getExcellentReadingName(){
		WebElement ele = this.findEle(excellent_reading_titel_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void excellentReadingView(Class name) throws MalformedURLException {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		//滑动到精品阅读
		driver.scrollTo("精品阅读");
		this.clickExcellentReading();
		log.info("点击进入精品阅读列表");
		this.clickExcellentReadingImage();
		log.info("该case测试通过！");
	}
}
